package com.yjz.middleware.ElasticSearch;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 废弃
 * Created by corning on 2018/3/5.
 */
//@Configuration
public class MyConfig {

  @Bean
  public TransportClient client() throws UnknownHostException {

    Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();

    PreBuiltTransportClient client = new PreBuiltTransportClient(settings);

    int[] local_ports = {9300};
    for (int port : local_ports) {
      client.addTransportAddress(new InetSocketTransportAddress(
        InetAddress.getByName("192.168.59.128"), port
      ));
    }

    return client;

  }

}
